﻿@model JustMVCTest.Models.PO
           @{ Html.EnableClientValidation(); }


@{
    ViewBag.Title = "Edit";
}



            <script type="text/javascript">
                $(function () {
                    $("#DeliveryDate").datepicker({ dateFormat: 'dd/mm/yy', minDate: 0 });
                  
                });

	            </script>



<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>


<font size="3" color="blue"> <b> Edit Details for  PO Number: @Html.DisplayFor(modelItem => modelItem.PONumber) Item Number: @Html.DisplayFor(modelItem => modelItem.Item) </b> </font>

  <br/>  <br/>


    <fieldset>
        <legend>Details</legend>
        <br/>
                <font size="3" color="gray"><b>PO Number:</b> </font>
                
                <font size="3" color="gray">@Html.DisplayFor(modelItem => modelItem.PONumber) &nbsp&nbsp&nbsp</font>

                <font size="3" color="gray"><b>Item Number:</b> </font>

                <font size="3" color="gray">@Html.DisplayFor(modelItem => modelItem.Item)&nbsp&nbsp&nbsp</font>
 
                <font size="3" color="gray"><b> Description: </b> </font>
 
                <font size="3" color="gray">@Html.DisplayFor(modelItem => modelItem.Descr)&nbsp&nbsp&nbsp</font>
                <font size="3" color="gray"> <b> Vendor Name: </b> </font>
 
                <font size="3" color="gray">@Html.DisplayFor(modelItem => modelItem.VendorName)&nbsp&nbsp&nbsp</font>
        
                <font size="3" color="gray"><b> Delivery Date:</b> </font>
    
                <font size="3" color="gray">@Html.DisplayFor(modelItem => modelItem.DeliveryDate)&nbsp&nbsp&nbsp</font>

                <br />
                <font size="3" color="red"><b> Percentage:</b> </font>

                <font size="3" color="red">@Html.DisplayFor(modelItem => modelItem.Percentage)&nbsp&nbsp&nbsp</font>

                <font size="3" color="red"><b>  Open Amount L:</b> </font>

                <font size="3" color="red">@Html.DisplayFor(modelItem => modelItem.Open_Amt_L)&nbsp&nbsp&nbsp</font>
           
                <font size="3" color="red"><b> Status:</b></font>
      
                <font size="3" color="red"> 
                    <script type="text/javascript">
                        var x = '@Html.DisplayFor(modelItem => modelItem.Status).ToHtmlString()'
                        if (x == '1') {
                            document.write("Pending Close");
                        }
                         if (x == '2'){
                             document.write("Pending Delivery Date"); 
                         }
                         if (x == '0') {
                             document.write("Open");
                         }
                         if (x == '99') {
                             document.write("Closed");
                         }

                    </script> </font>
        <br/>
    </fieldset>
    
    

    <fieldset>
        <legend>Edit</legend>
        <table style="border-color:transparent; border-width:thick">

        @using (Html.BeginForm(null, null, FormMethod.Post, new { name = "myform", id = "myform" }))
        {

        <tr style="border-color:transparent; border-width:thick"> 

        <td style="border-color:transparent; border-width:thick"> 

           @Html.ValidationSummary()
           
           @if (Model.Status != 2 && Model.Status != 1)
           {
                <input type='radio' name='status' id="status2" value='2' />
                
               <span onclick="document.getElementById('status2').checked = true;" style="font-weight:bold;">
               Edit Delivery Date: 
               </span>
           }

              <font size='2'>
            @Html.HiddenFor(model => model.PONumber)
            @Html.HiddenFor(model => model.Item)
            @Html.HiddenFor(model => model.Update_Num)
         

           @if (Model.DeliveryDate > DateTime.Now)
                 {
                  
                  if (Model.Status != 2 && Model.Status != 1)
                    {
                        
                        @(Html.Telerik().DatePicker()
                        .Name("DeliveryDate_Req")
                        .Min(Model.DeliveryDate)
                        .Value(Model.DeliveryDate)
                        );
                        
                        @Html.ValidationMessageFor(x => x.DeliveryDate_Req) 
                        
                        //@Html.ValidationMessage("DeliveryDate_Req", "*") 
                    }

                 }
                  
               @if (Model.DeliveryDate <= DateTime.Now)
               {

                   if (Model.Status != 2 && Model.Status != 1)
                   {
                        @(Html.Telerik().DatePicker().Name("DeliveryDate_Req").Min(DateTime.Now).Value(DateTime.Now));
                        @Html.ValidationMessageFor(x => x.DeliveryDate_Req) 
                        
                        //@Html.ValidationMessage("DeliveryDate_Req", "*") 
                   }

               }

               
 
            </font>
            </td> 

            </tr> 
            <tr style="border-color:transparent; border-width:thick">

                <td style="border-color:transparent; border-width:thick">
            
           
                      
           @if (Model.Status != 2 && Model.Status != 1)
           {
                <input type="radio" name="status" id="status1" value="1" />
                <span onclick="document.getElementById('status1').checked = true;" style="font-weight:bold;">Close PO</span>
                <!-- <font size="3" color="gray" >Close PO</font> -->
           }
           
           
            <font size="2">

            @Html.HiddenFor(model => model.PONumber)
            @Html.HiddenFor(model => model.Item)

            </font>
                </td> 

                </tr>

                              <tr>
        <td style="border-color:transparent; border-width:thick">
        <input type="radio" name="status" id="status66" value="66" checked />
        
        
        <span onclick="document.getElementById('status66').checked = true;" style="font-weight:bold;color:Black;">
        Change PO Percentage: 
        </span>
        
            <font size="2">

            @Html.HiddenFor(model => model.PONumber)
            @Html.HiddenFor(model => model.Item)
            @Html.HiddenFor(model => model.DeliveryDate_Req)

            <select name="Percentage" id="Percentage" onfocus="document.getElementById('status66').checked = true;">
            
            <option value="@Html.DisplayFor(modelItem => modelItem.Percentage)"> @Html.DisplayFor(modelItem => modelItem.Percentage) </option>
            <script type="text/javascript">
            var per;
            per = @Html.DisplayFor(modelItem => modelItem.Percentage)+10;
            while (per <= 100) {
            document.write('<option value="');
            document.write(per);
            document.write('">');
            document.write(per);
            document.write("</option>");
            per = per+10;
            }</script>
            </select>
            
            </font></td> 
            
                                  
        </tr>   
            
                                         
        <tr>
            
        <td style="border-color:transparent; border-width:thick">
        
        <input type="radio" name="status" id="status67" value="67" />

        <span onclick="document.getElementById('status67').checked = true;" style="font-weight:bold;color:Black;">
        Change Open Amount L: 
        </span>

            <font size="2">

            @Html.HiddenFor(model => model.PONumber)
            @Html.HiddenFor(model => model.Item)
            @Html.HiddenFor(model => model.DeliveryDate_Req)
            @*<input type="hidden" value="67" name="status" />*@
            <input type="text" name="Open_Amt_L" onfocus="document.getElementById('status67').checked = true;" />
            
            </font></td> 
            
            </tr> 
            
            <tr> 

            <td>
                 
                    <script type="text/javascript">
                    function isNumber(n) {
                                return !isNaN(parseFloat(n)) && isFinite(n);
                    }

                    function isValidDate(s) {
                    var bits = s.split('/');
                    var d = new Date(bits[2], bits[1] - 1, bits[0]);
                    return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]);
                    } 
                    
                    
                    function checkform() {
                      

                        for (var i=0; i < document.myform.status.length; i++)
                        {
                            if (document.myform.status[i].checked)
                            {
                                var rad_val = document.myform.status[i].value;
                                
                                switch(rad_val)
                                {
                                    case "1": //close
                                        break;

                                    case "2": //delivery date
                                        
                                        if (!isValidDate(document.myform.DeliveryDate_Req.value))
                                        {
                                            alert("not a valid date format");
                                            return false;
                                        }
                                        break;

                                    case "66": //percentage
                                        break;

                                    case "67": //open amount l
                                        if (!isNumber(myform.Open_Amt_L.value))
                                        {
                                           alert('Open Amount L value is not numeric');
                                           return false;
                                        }
                                         
                                        if (myform.Open_Amt_L.value < 0)
                                        {
                                            alert('Open amount may not be negative');
                                            return false;
                                        }

                                        if (myform.Open_Amt_L.value >= @Model.Open_Amt_L)
                                        {
                                            alert('You may only lower the open amount');
                                            return false;
                                        }
                                        break;
                                    }
                                }
                        }
                        
                       return true;
                    }
                    
                    function aeye() 
                    {
                        alert('Aeye!');
                        return false;
                    }
                    </script>
                 
                 
                 <input onclick="return checkform();" type="submit" value="Save Changes" />
            </td>

            </tr> 
            
        }
              </table>

    </fieldset>


